<%@ page import="java.io.*,java.util.*,java.sql.*" %> 

    <%

    int id=0;

    if(request.getParameter("id")!=null && request.getParameter("id")!="")

    {

    id = Integer.parseInt(request.getParameter("id").toString());

    }

         String connectionURL = "jdbc:mysql://localhost/myDataBase";

          String url=request.getParameter("WEB_URL");

          String Content=new String("");
          String filename=new String("");
          Statement stmt=null;

      Connection con=null;

    try

    {

	      
	
	      Class.forName("com.mysql.jdbc.Driver").newInstance();
		  
	      con=DriverManager.getConnection(connectionURL,"root","a123456"); 
	
	      stmt=con.createStatement();
	      String qry = "select * from files where file_id="+id;
	
	      ResultSet rst= stmt.executeQuery(qry);
	      if(rst.next())
	
	      {
	
	
	    	      filename=rst.getString("name");
	      }
	      
	      out.println(Content);
	      String dir=new File(".").getAbsolutePath();
		  Content=dir+System.getProperty("file.separator")+Content;
          byte requestBytes[] =  Content.getBytes();

          ByteArrayInputStream bis = new ByteArrayInputStream(requestBytes);

  
          response.reset();

          response.setContentType("application/text");

          response.setHeader("Content-disposition","attachment; filename=" + filename);

          byte[] buf = new byte[1024];

            int len;

            while ((len = bis.read(buf)) > 0){

                            response.getOutputStream().write(buf, 0, len);

                           }

          bis.close();

          response.getOutputStream().flush(); 
                        
			    

    }

    catch(Exception e){

        e.printStackTrace();

    }

    %>